package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.QuestionItemMapper;
import com.fc.test.model.auto.QuestionItem;
import com.fc.test.model.auto.QuestionItemExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * 题目内容 QuestionItemService
 * @Title: QuestionItemService.java 
 * @Package com.fc.test.service 
 * @author martins_自动生成
 * @email 610817750@qq.com
 * @date 2019-12-03 13:03:43  
 **/
@Service
public class QuestionItemService implements BaseService<QuestionItem, QuestionItemExample>{
	@Autowired
	private QuestionItemMapper questionItemMapper;
	
      	   	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<QuestionItem> list(Tablepar tablepar,String name){
	        QuestionItemExample testExample=new QuestionItemExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andTypeIdEqualTo(name);
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<QuestionItem> list= questionItemMapper.selectByExample(testExample);
	        PageInfo<QuestionItem> pageInfo = new PageInfo<QuestionItem>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			QuestionItemExample example=new QuestionItemExample();
			example.createCriteria().andIdIn(lista);
			return questionItemMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public QuestionItem selectByPrimaryKey(String id) {
				
			return questionItemMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(QuestionItem record) {
		return questionItemMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(QuestionItem record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return questionItemMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(QuestionItem record, QuestionItemExample example) {
		
		return questionItemMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(QuestionItem record, QuestionItemExample example) {
		
		return questionItemMapper.updateByExample(record, example);
	}

	@Override
	public List<QuestionItem> selectByExample(QuestionItemExample example) {
		
		return questionItemMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(QuestionItemExample example) {
		
		return questionItemMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(QuestionItemExample example) {
		
		return questionItemMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param questionItem
	 * @return
	 */
	public int checkNameUnique(QuestionItem questionItem){
		QuestionItemExample example=new QuestionItemExample();
		example.createCriteria().andTypeIdEqualTo(questionItem.getTypeId());
		List<QuestionItem> list=questionItemMapper.selectByExample(example);
		return list.size();
	}


	public List<QuestionItem> listByQuestionId(String id) {
		QuestionItemExample testExample=new QuestionItemExample();
		testExample.setOrderByClause("code ASC");
		testExample.createCriteria().andTypeIdEqualTo(id);

		return questionItemMapper.selectByExample(testExample);
	}
}
